﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace sqlsearcher.Models
{
    public class BianQianData
    {
        public static Dictionary<string, string> data = new Dictionary<string, string>();
        public void Add(ListView listView,string name,string content)
        {
            listView.Items.Add(name);
            if (data.ContainsValue(content))
            {
                data[name] = "";
            }
            else
            {
                data[name] = content;
            }
        }

        public void Update(ListView listView, string content)
        {
            foreach (ListViewItem item in listView.Items)
            {
                if (item.Selected)
                {
                    data[item.Text] = content;
                    return;
                }
            }
        }

        public void Delete(ListView listView)
        {
            try
            {
                foreach (ListViewItem item in listView.Items)
                {
                    if (item.Selected)
                    {
                        data.Remove(item.Text);
                        listView.Items.Remove(item);
                        break;
                    }
                }
            }
            catch (Exception e)
            {

            }
        }

        public string Get(ListView listView)
        {
            foreach (ListViewItem item in listView.Items)
            {
                if (item.Selected)
                {
                    return data[item.Text];
                }
            }
            return "";
        }
    }
}
